2015年信息学奥赛NOIP普及组
初赛
更早
2023-08-23 14:45:22
92次
一、单选题
二、填空题
#include <iostream>
using namespace std;
struct point
{
int x;
int y;
};
int main()
{
int a, b, c;
struct EX
{
int a;
int b;
point c;
}e;
e.a = 1;
e.b = 2;
e.c.x = e.a + e.b;
e.c.y = e.a * e.b;
cout << e.c.x << ',' << e.c.y << endl;
return 0;
}输出:
【知识点】 信息学NOIP普及组
#include <iostream>
#include <string>
using namespace std;
int main()
{
string str;
int i;
int count;
count = 0;
getline(cin, str);
for(i = 0; i < str.length(); i++)
if(str[i] >= 'a' && str[i] <= 'z')
count++;
cout << "It has " << count << " lowercases" << endl;
return 0;输入: NOI2016 will be held in Mian Yang.
输出:
【知识点】 信息学NOIP普及组
三、简答题
完善程序:(中位数 median)给定 n(n 为奇数且小于 1000)个整数, 整数的范围在 0~m(0<m<2^31)之间, 请使 用二分法求这 n 个整数的中位数。所谓中位数,是指将这 n 个数排序之后,排在正中间的数。 (第五空 2分,其余 3 分)
#include <iostream>
using namespace std;
const int MAXN = 1000;
int n, i, lbound, rbound, mid, m, count;
int x[MAXN];
int main()
{
cin >> n >> m;
for(i = 0; i < n; i++)
cin >> x[i];
lbound = 0;
rbound = m;
while( ⑴ )
{
mid = (lbound + rbound) / 2;
⑵ ;
for(i = 0; i < n; i++)
if( ⑶ )
⑷ ;
if(count > n / 2)
lbound = mid + 1;
else
⑸ ;
cout << mid << " " << lbound << " " << rbound << " " << count << endl;
}
cout << rbound << endl;
return 0;
}
【知识点】 信息学NOIP普及组
完善程序: (打印月历)输入月份 m(1≤m≤12),按一定格式打印 2015 年第 m 月的月历。 (第三、四空 2.5 分,其余 3 分)
例如,2015 年 1 月的月历打印效果如下(第一列为周日):

#include <iostream>
#include <string>
using namespace std;
const int dayNum[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int m, offset, i;
int main()
{
cin >> m;
cout << "S\tM\tT\tW\tT\tF\tS" << endl; //'\t'为 TAB 制表符
⑴ ;
for(i = 1; i < m; i++)
offset = ⑵ ;
for(i = 0; i < offset; i++)
cout << '\t';
for(i = 1; i <= ⑶ ; i++)
{
cout << ⑷ ;
if(i == dayNum[m] || ⑸ == 0)
cout << endl;
else
cout << '\t';
}
return 0;
}
【知识点】 信息学NOIP普及组
